using System.Reflection;
using System.Security.Authentication;
using Agatha.Common;
using Agatha.Common.InversionOfControl;
using Agatha.ServiceLayer;
using Source.Common;

namespace Source.ServiceLayer
{
    public static class ComponentInitialization
    {
        public static void InitializeAllComponents()
        {
            RegisterRequestAndHandlers();
            RegisterVariousComponents();

        }

        public static void RegisterRequestAndHandlers()
        {
            var config = new
                ServiceLayerConfiguration(Assembly.GetExecutingAssembly(),
                                          typeof (HelloWorldRequest).Assembly,
                                          typeof (Agatha.Castle.Container))
                             {
                                 SecurityExceptionType = typeof (AuthenticationException),
                                 BusinessExceptionType = typeof (BusinessException)
                             };

            config.Initialize();

        }

        private static void RegisterVariousComponents() 
        {
            IoC.Container.Register(typeof(IServerSideUserManager),typeof(UserManager), Lifestyle.Transient);
            IoC.Container.Register(typeof(ITokenProvider),typeof(TokenProvider), Lifestyle.Singleton);
            IoC.Container.Register(typeof(IOlaMembershipProvider),typeof(MembershipProviderWrapper), Lifestyle.Transient);
            IoC.Container.Register(typeof(ISessionTokenCache),typeof(SessionTokenCache), Lifestyle.Singleton);
            IoC.Container.Register(typeof(IAuthenticationManager),typeof(AuthenticationManager), Lifestyle.Transient);
            IoC.Container.Register(typeof(IAdministrationAuthorization),typeof(AdministrationAuthorization), Lifestyle.Transient);
            IoC.Container.Register(typeof(IConfigurationProvider), typeof(ConfigurationProvider), Lifestyle.Transient);
        }

      

    }

    
}
